package interfaces.console.commands.descriptors;

import main.ResolutionHandler;

import fileHandling.language.LanguageLoader;
import fileHandling.language.options.OptionValues;

import interfaces.inputValidation.FloatInputChecker;
import interfaces.inputValidation.InputChecker;
import interfaces.inputValidation.IntegerBoundsChecker;
import interfaces.inputValidation.KeyInputChecker;
import interfaces.inputValidation.TextInputChecker;
import interfaces.options.OptionWidgetFactory;
import interfaces.options.OptionWidgetFactory.OptionType;

public class OptionDescriptor {
			
	protected InputChecker checker;
	protected String fileName, commandName;
	protected OptionWidgetFactory factory;
	
	public OptionDescriptor(String commandName, String fileName) {
		this.commandName = commandName;
		this.fileName = fileName;
		
		factory = new OptionWidgetFactory(fileName, null);
		checker = getChecker();
	}
	
	public String checkArgument(String argument) {
		if(checker.isValid(argument)) return null;
		return checker.getDescription();
	}
	
	private int getMin() {
		return factory.getMin(factory.getElement(commandName));
	}
	
	private int getMax() {
		return factory.getMax(factory.getElement(commandName));
	}
	
	private String[] getValues() {
		return factory.getValues(factory.getElement(commandName));
	}
	
	protected InputChecker getChecker() {
		OptionType type = factory.getType(factory.getElement(commandName));
		
		switch(type) {
			case Antialiasing: return new TextInputChecker(OptionValues.Off.toString(), "2x", "4x", "8x");
			case Bool: return new TextInputChecker("true", "false");
			case Float: return new FloatInputChecker();
			case Int: return new IntegerBoundsChecker(getMin(), getMax());
			case Key: return new KeyInputChecker();
			case Lang: return new TextInputChecker(getValues());
			case Language: return new TextInputChecker(LanguageLoader.getInstalledLanguages());
			case Level: String high = OptionValues.High.toString();
						String medium = OptionValues.Medium.toString();
						String low = OptionValues.Low.toString();
						return new TextInputChecker(high, medium, low);
			case Resolution: return new TextInputChecker(ResolutionHandler.get().getSortedResolutions());
		}
		return null;
	}
}